//
//  main.m
//  C06_2_结构体
//
//  Created by dllo on 15/11/24.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Person.h"   // 导入头文件

int main(int argc, const char * argv[]) {

    /** 定义Person结构体类型变量 */
    Person per1 = {"wangQiang", 80, 'm', 1};
    Person per2 = {"wangYan", 90, 'f', 2};
    Person per3 = {"blackSix", 50, 'm', 3};
    
    
    InformationOfPerson(per1);
    InformationOfPerson(per2);
    
    /** 定义一个数组 */
    Person arrPerson[3] = {per1, per2, per3};
    
    /** 需求:将数组中的元素按照年龄的大小升序排序 */
    
    Person temp = {};
    for (int i = 0; i < 3 - 1; i++) {
        for (int j = 0; j < 3 - 1 - i; j++) {
            if (arrPerson[j].age > arrPerson[j + 1].age) {
                temp = arrPerson[j];
                arrPerson[j] = arrPerson[j + 1];
                arrPerson[j + 1] = temp;
            }
        }
    }
    for (int i = 0; i < 3; i++) {
        InformationOfPerson(arrPerson[i]);
    }

    /** 需求:将数组中的元素按照姓名升序排序 */
    
    for (int i = 0; i < 3 - 1; i++) {
        for (int j = 0; j < 3 - i - 1; j++) {
            if (strcmp(arrPerson[j].name, arrPerson[j + 1].name) > 0) {
                temp = arrPerson[j];
                arrPerson[j] = arrPerson[j + 1];
                arrPerson[j + 1] = temp;
            }
        }
    }
    for (int i = 0; i < 3; i++) {
        InformationOfPerson(arrPerson[i]);
    }
    
    
    
    

    
    
    
    
    
    
    return 0;
}
